import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import { getInfo } from "@/api/home";

/**
 * 获取页面轮播图的 hooks 参数从路由中获取
 * @returns banners 轮播图list
 */
export default function useBanner() {
    const route = useRoute();
    const banners = ref<string[]>();

    // 获取轮播图数据
    async function getBannerData(): Promise<string[]> {
        const res = await getInfo(route.name as string);
        console.log(res.data);

        let banners = res.data.data.imgUrl.split(",");
        return banners;
    }
    onMounted(async () => {
        // 获取轮播图数据
        banners.value = await getBannerData();
    });
    return {
        banners,
    };
}
